home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Small Eiffel 0.4.8 / lib_std / double_ref.e < prev    next >
Text File  |  1997-04-13  |  2KB  |  114 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class DOUBLE_REF
  5.  
  6. inherit
  7.    NUMERIC
  8.       undefine out_in_tagged_out_memory, fill_tagged_out_memory
  9.       redefine
  10.      infix "^", prefix "+", prefix "-"
  11.       end;
  12.    COMPARABLE
  13.       redefine
  14.      compare, out_in_tagged_out_memory, fill_tagged_out_memory
  15.       end;
  16.  
  17. creation make
  18.  
  19. feature 
  20.  
  21.    item: DOUBLE;
  22.  
  23.    make(value: DOUBLE) is
  24.       do
  25.      item := value
  26.       end;
  27.    
  28. feature
  29.    
  30.    set_item(value: like item) is
  31.       do
  32.      item := value;
  33.       end;
  34.  
  35.    infix "+" (other: like Current): like Current is
  36.      -- Add `other' to Current.
  37.       do
  38.      !!Result.make (item + other.item)
  39.       end;
  40.  
  41.    infix "-" (other: like Current): like Current is
  42.      -- Subtract `other' from Current.
  43.       do
  44.      !!Result.make (item - other.item);
  45.       end;
  46.  
  47.    infix "*" (other: like Current): like Current is
  48.      -- Multiply `other' by Current.
  49.       do
  50.      !!Result.make (item * other.item)
  51.       end;
  52.  
  53.    infix "/" (other: like Current): like Current is
  54.      -- Divide Current by `other'.
  55.       do
  56.      !!Result.make (item / other.item)
  57.       end;
  58.  
  59.    infix "^" (exp: INTEGER): like Current is
  60.      -- Raise Current to `exp'-th power.
  61.       do
  62.      !!Result.make (item ^ exp)
  63.       end;
  64.  
  65.    prefix "+" : like Current is
  66.       do
  67.      !!Result.make (item)
  68.       end;
  69.  
  70.    prefix "-" : like Current is
  71.       do
  72.      !!Result.make (-item);
  73.       end;
  74.  
  75.    infix "<" (other: like Current): BOOLEAN is
  76.      -- Is Current less than `other'?
  77.       do
  78.      Result := item < other.item
  79.       end;
  80.  
  81.    compare (other: like Current): INTEGER is
  82.      -- Compare Current with `other'.
  83.      -- '<' <==> Result < 0
  84.      -- '>' <==> Result > 0
  85.      -- Otherwise Result = 0
  86.       do
  87.      Result := item.compare (other.item)
  88.       end;
  89.  
  90.    valid_divisor (other: like Current): BOOLEAN is
  91.       do
  92.      Result := (other.item /= 0.0)
  93.       end;
  94.  
  95.    one: like Current is
  96.       do
  97.      !!Result.make (1.0)
  98.       end;
  99.  
  100.    zero: like Current is
  101.       do
  102.      !!Result.make (0.0)
  103.       end;
  104.  
  105. feature -- Object Printing :
  106.  
  107.    out_in_tagged_out_memory, fill_tagged_out_memory is
  108.       do
  109.      tagged_out_memory.append("item: "); 
  110.      item.fill_tagged_out_memory;
  111.       end;
  112.  
  113. end -- DOUBLE_REF
  114.